﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace CompanyBussiness
{
    public class CheckValid
    {
        /// <summary>
        /// ChechName()
        /// </summary>
        /// <param name="name"></param>
        /// <returns>bool</returns>
        public bool ChechName(string name)
        {
            Regex reString = new Regex(@"^[a-zA-Z0-9_]*$");   //Tên chỉ bao gồm chữ và số

            if (!reString.IsMatch(name))
                return false;
            return true;
        }
        /// <summary>
        /// CheckNumber()
        /// </summary>
        /// <param name="numBer"></param>
        /// <returns></returns>
        public bool CheckNumber(string numBer)
        {
            Regex reString = new Regex(@"^([-]|[.]|[-.]|[0-9])[0-9]*[.]*[0-9]+$");          //số thực

            if (!reString.IsMatch(numBer))
                return false;
            return true;
        }
        /// <summary>
        /// CheckEmail()
        /// </summary>
        /// <param name="email"></param>
        /// <returns>bool</returns>
        public bool CheckEmail(string email)
        {
            Regex reString = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");

            if (!reString.IsMatch(email))
                return false;
            return true;
        }
        /// <summary>
        /// CheckDate()
        /// </summary>
        /// <param name="date"></param>
        /// <returns>bool</returns>
        public bool CheckDate(DateTime date)
        {
            if (date.Year > DateTime.Now.Year)
            {
                return true;
            }
            else if (date.Year == DateTime.Now.Year)
            {
                if (date.Month > DateTime.Now.Month)
                    return true;
                else if (date.Month == DateTime.Now.Month)
                {
                    if (date.Day > DateTime.Now.Day || date.Day == DateTime.Now.Day)
                        return true;
                    return false;
                }
            }
            return false;
        }
        /// <summary>
        /// CheckPhone()
        /// </summary>
        /// <param name="phone"></param>
        /// <returns>bool</returns>
        public bool CheckPhone(string phone)
        {
            try
            {
                Convert.ToInt64(phone);
                return true;
            }
            catch (FormatException ex)
            {
                Console.Write(ex);
                return false;
            }
        }
        /// <summary>
        /// CheckSearch()
        /// </summary>
        /// <param name="strSearch"></param>
        /// <returns>bool</returns>
        public bool CheckSearch(string strSearch)
        {
            Regex reString = new Regex(@"\w{3,20}");
            if (!reString.IsMatch(strSearch))
                return false;
            return true;
        }
        /// <summary>
        /// Doi ngay thang 
        /// </summary>
        /// <param name="_strDate"></param>
        /// <param name="_type">Phan biet du lieu vao va ra (_type = 1:vao; _type = -1:ra)</param>
        /// <returns></returns>
        //public string DateAlter(string _strDate, int _type)
        //{
        //    string[] dateArray = _strDate.Split('/');

        //    string newDate = "";
        //    newDate += dateArray[1] + "/" + dateArray[0] + "/" + dateArray[2];
        //    if (_type == 1)
        //    {
        //        try
        //        {
        //            DateTime testDate = new DateTime();
        //            testDate = Convert.ToDateTime(newDate);
        //        }
        //        catch (Exception ex)
        //        {
        //            return "NonOK";
        //        }
        //    }
        //    return newDate;
        //}
        public bool ConvertIntToBool(string num)
        {
            if (num == "1")
                return true;
            else
                return false;
        }
    }
}
